﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaseLibrary
{
   public class DBHelper
    {
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <returns></returns>
        public static string getConnString(string Name)
        {

            //            <?xml version="1.0" encoding="utf-8" ?>
            //<configuration>

            //    <connectionStrings>

            //        <add name="DYDB" providerName="Oracle" connectionString="Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 134.44.36.51)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 134.44.36.52)(PORT = 1521)) )  (CONNECT_DATA =  (SERVICE_NAME = dydb)   )  );User Id=weibh;Password=1234;"/>

            //    </connectionStrings>
            //</configuration>

            string filePath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Replace(@"file:///", string.Empty) + ".config";
            System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
            xDoc.Load(filePath);
            return xDoc.SelectSingleNode(@"/configuration/connectionStrings/add[@name='" + Name + "']").Attributes["connectionString"].Value;
        }
    }
}
